package com.suneast.suneaststore.modules.personal.trace.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.personal.trace.TraceAdapterBean;
import com.suneast.suneaststore.bean.personal.trace.TraceBean;

import java.util.List;

public class TraceAdapter extends BaseQuickAdapter<TraceAdapterBean, BaseViewHolder> {

    private boolean showCheckBox;

    public TraceAdapter(int layoutResId, @Nullable List<TraceAdapterBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TraceAdapterBean item) {
        helper.setText(R.id.tv_date, item.getDateStr());
        RecyclerView rv = helper.getView(R.id.rv_item_trace);
        GridLayoutManager gridLayoutManager =
                new GridLayoutManager(helper.itemView.getContext(), 3);
        rv.setLayoutManager(gridLayoutManager);
        TraceItemAdapter adapter = new TraceItemAdapter(R.layout.item_trace_item, item.getTraceBeanList());
        adapter.setShowCheckBox(showCheckBox);
        adapter.setOnItemClickListener((BaseQuickAdapter traceItemAdapter, View view, int position) -> {
            if (listener != null) {
                TraceBean bean = (TraceBean) traceItemAdapter.getData().get(position);
                listener.onItemTraceClick(bean);
            }
        });
        rv.setAdapter(adapter);
    }

    private OnItemTraceClickListener listener;

    public void setItemTraceClickListener(OnItemTraceClickListener listener) {
        this.listener = listener;
    }

    public interface OnItemTraceClickListener {
        void onItemTraceClick(TraceBean bean);
    }

    public void setShowCheckBox(boolean showCheckBox) {
        this.showCheckBox = showCheckBox;
    }
}
